

package org.t2.design.module.autogen;


public abstract class EveryDayAbstractTable<T extends EveryDayAbstractTable.EveryDayCfg> extends org.gaming.design.loader.DesignCache<T> {

	@Override
	public final String fileName() {
		return "M-每日礼包";
	}
	
	
	protected java.util.Map<String, T> IdIndex;
	
	/**
	 * 从索引中获取对象，获取不到会抛异常
	 */
	public final T getInIdIndex(
		int Id
	) {
		String key = "" + Id;
		T t = IdIndex.get(key);
		if(t == null) {
			throw new org.gaming.design.exception.DesignNotFoundException("EveryDayTable when getInIdIndex", key);
		}
		return t;
	}
	
	/**
	 * 从索引中查找对象，获取不到会返回null
	 */
	public final T findInIdIndex(
		int Id
	) {
		String key = "" + Id;
		return IdIndex.get(key);
	}
	
	/**
	 * 加载IdIndex索引
	 */
	private final void loadIdIndex() {
		java.util.Map<String, T> IdIndex = new java.util.HashMap<>();
		for(T data : all()) {
			String[] keys = new String[] {
				String.valueOf(data.getId()),
			};
			String key = String.join("_", keys);
			if(IdIndex.containsKey(key)) {
				logger.error("{} found duplicate key {} in index {}", fileName(), key, IdIndex);
				super.hasError = true;
			}
			IdIndex.put(key, data);
		}
		this.IdIndex = IdIndex;
	}
	
	
	
	@Override
	protected final void loadAutoGenerate() {
		//加载索引
		loadIdIndex();
	
		
	}
	
	public static class EveryDayCfg {
		//ID
		protected int Id;
		/**
		 * getID
		 */
		public int getId() {
			return Id;
		}
		//物品[物品id,数量]
		protected java.util.List<org.t2.design.struct.RewardThing> Reward;
		/**
		 * get物品[物品id,数量]
		 */
		public java.util.List<org.t2.design.struct.RewardThing> getReward() {
			return Reward;
		}
	}

}